
public class HadamardMatrix {
	private int nbUser;
	private int [][] matriceH2 = { {1,1},{1,-1} };
	private int [][] matrice ;
	private int indice = 0;
	private  int nbLines = 2;
	
	public HadamardMatrix(int nb) {
		this.nbUser = nb;
	}

	public void generate() {
		int [][] matriceTmp ;
		int comptL = 0;
		int comptC = 0;
		matrice = matriceH2;
		int cpt = 2;
		while(nbLines < this.nbUser){
			nbLines *= 2;
			cpt++;
		}
		
		for (int compt = 2 ; compt < cpt ; compt++) {
			indice++;
			comptL = 0;
			comptC = 0;
			matriceTmp = new int[matriceH2.length * matrice.length][matriceH2[0].length * matrice[0].length];
			for (int i = 0 ; i < matriceH2.length ; i++) {
				comptC = 0;
				for (int j = 0 ; j < matriceH2[i].length ; j++) {
					for (int z = 0 ; z < matrice.length ; z++) {
						for (int x = 0 ; x < matrice[z].length ; x++) {
							matriceTmp[i+z+comptL][j+x+comptC] = matriceH2[i][j] * matrice[z][x];
						}
					}
					comptC+=matrice[0].length-1;
				}
				comptL+=matrice.length-1;
				nbLines *= 2;
			}
			matrice = matriceTmp;
		}
	}
	
    public void generate2() {
        int [][] matriceTmp ;
        int comptL = 0;
        int comptC = 0;
        matrice = matriceH2;
        for (int compt = 2 ; compt < this.nbUser ; compt++) {
                comptL = 0;
                comptC = 0;
                matriceTmp = new int[matriceH2.length * matrice.length][matriceH2[0].length * matrice[0].length];
                for (int i = 0 ; i < matriceH2.length ; i++) {
                        comptC = 0;
                        for (int j = 0 ; j < matriceH2[i].length ; j++) {
                                for (int z = 0 ; z < matrice.length ; z++) {
                                        for (int x = 0 ; x < matrice[z].length ; x++) {
                                                matriceTmp[i+z+comptL][j+x+comptC] = matriceH2[i][j] * matrice[z][x];
                                        }
                                }
                                comptC+=matrice[0].length-1;
                        }
                        comptL+=matrice.length-1;
                }
                matrice = matriceTmp;
        }
}
	
	public int[] getLine(int nbLine){
		//int[] line = new int[this.nbLines];
		int[] line = new int[matrice.length];
		for (int j = 0 ; j < matrice[nbLine].length ; j++) {
			line[j] += matrice[nbLine][j];
		}
		return line;
	}
	
	public String toString() {
		
		String str = "";
		for (int i = 0 ; i < matrice.length ; i++) {
			for (int j = 0 ; j < matrice[i].length ; j++) {
				str += matrice[i][j] + "\t|\t";
			}
			str += "\n";
		}
		return str;
	}

	public int getNbLines() {
		//return nbLines;
		return matrice.length;
	}

	public int getIndice() {
		return indice;
	}
	
	
	
	
}
